import unittest

import app
from aip.employee import EmployeeAPI

# 创建测试类
from utils import common_assert


class TestEmployee(unittest.TestCase):
    # 定义员工id
    employee_id = None

    def setUp(self) -> None:
        self.employee_api = EmployeeAPI()

    # 添加员工测试用例
    def test01_add_employee(self):
        add_employee_data = {
                "username": "jack0709t2", # 唯一
                "mobile": "13212322174", # 唯一
                "timeOfEntry": "2020-07-09",
                "formOfEmployment": 1,
                "workNumber": "10085", # 唯一
                "departmentName": "销售",
                "departmentId": "1266699057968001024",
                "correctionTime": "2020-07-30T16:00:00.000Z"
        }

        # 获取响应结果
        response = self.employee_api.add_employee(add_employee_data)
        print(response.json())
        # common_assert(self, response, 200, True, 10000, "操作成功")
        common_assert(self, response) # utils中设置了默认值

        # 提取员工ID
        TestEmployee.employee_id = response.json().get("data").get("id")
        print("员工id：", TestEmployee.employee_id)

    # 修改员工测试用例
    def test02_modify_employee(self):
        modify_employee_data = {
            "username": "jack12"  # 唯一
        }

        # 获取响应结果
        response = self.employee_api.modify_employee(employee_id=TestEmployee.employee_id, update_data=modify_employee_data)
        print(response.json())

        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))

    # 查询员工测试用例
    def test03_get_employee(self):
        # 获取响应结果
        response = self.employee_api.get_employee( employee_id=TestEmployee.employee_id)
        print(response.json())

        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))

    #  删除员工测试用例
    def test04_delete_employee(self):

        # 获取响应结果
        response = self.employee_api.delete_employee( employee_id=TestEmployee.employee_id)
        print(response.json())

        # 断言
        self.assertEqual(200, response.status_code)
        self.assertEqual(True, response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertIn("操作成功", response.json().get("message"))
